package com.itheima.util;

import io.jsonwebtoken.*;

import java.util.Date;
import java.util.Map;


public class JwtUtils {


    private static String signKey = "SVRIRUlNQQ==";
    private static Long expire = 43200000L;
    /**
     * 生成JWT令牌
     * @return
     */

    public static String generateJwt(Map<String , Object> claims){
        String jwt= Jwts.builder()
                .addClaims( claims)
                .signWith(SignatureAlgorithm.HS256,signKey)
                .setExpiration(new Date(System.currentTimeMillis()+expire))
        .compact();
        return jwt;
    }




    public static Map<String ,Object> paraseJwt(String jwt){

        Claims body = null;
        try {
            body = Jwts.parser()
                   .setSigningKey(signKey)
                   .parseClaimsJws(jwt)
                   .getBody();
        } catch (Exception e) {

        }

        return body;
    }




}
